package org.scala.javafx.diagnostics

import javafx.beans.value.ObservableValue
import javafx.beans.value.WritableValue
import javafx.collections.ObservableList
import javafx.scene.control.Control
import javafx.scene.control.Label
import javafx.scene.control.TreeCell
import javafx.scene.input.MouseButton
import javafx.scene.layout.Region
import javafx.scene.layout.Pane
import javafx.scene.Node
import javafx.scene.Scene
import org.scala.javafx.rich.Enrich._

class SpyCell extends TreeCell[SpyInfo] {
  override def updateItem(spyInfo: SpyInfo, empty: Boolean): Unit = {
    super.updateItem(spyInfo, empty)
    
    if (spyInfo == null) {
      setText("null")
    } else {
      val typeLabel = spyInfo.item match {
        case control: WritableValue[_] => {
          val label = new Label("P")
          label.setStyle("-fx-text-fill: green; -fx-font-weight: bold;")
          label
        }
        case control: ObservableValue[_] => {
          val label = new Label("P")
          label.setStyle("-fx-text-fill: red; -fx-font-weight: bold;")
          label
        }
        case control: ObservableList[_] => {
          val label = new Label("L")
          label.setStyle("-fx-text-fill: purple; -fx-font-weight: bold;")
          label
        }
        case control: Scene => new Label("S")
        case node: Node => new Label("N")
        case _ => new Label("O")
      }
      setText(spyInfo.name + ": " + spyInfo.itemString)
      this.setGraphic(typeLabel)
    }
  }
  
  this.onMouseClicked { mouseEvent =>
    if (mouseEvent.getButton() == MouseButton.SECONDARY) {
    }
  }
}
